home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / mosmllib / Timer.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  1.3 KB  |  44 lines  |  [TEXT/R*ch]

  1. (* Timer -- new basis 1995-03-20, 1995-09-14, 1995-11-06, 1997-03-07 *)
  2.  
  3. (* Under DOS, real time and cpu time are the same *)
  4.  
  5. local 
  6.     type tusage = { gcSec : int,  gcUsec : int,
  7.                    sysSec : int, sysUsec : int,
  8.                    usrSec : int, usrUsec : int  }
  9.     prim_val getrutime_ : unit -> tusage = 1 "sml_getrutime"
  10.     open Time
  11. in
  12.     type cpu_timer  = {usr : time, sys : time, gc : time};
  13.     type real_timer = time;
  14.  
  15.     fun startCPUTimer () = 
  16.     let val {gcSec, gcUsec, sysSec, sysUsec, usrSec, usrUsec} 
  17.             = getrutime_ () 
  18.     in {usr = fromSeconds usrSec + fromMicroseconds usrUsec,
  19.         sys = fromSeconds sysSec + fromMicroseconds sysUsec,
  20.         gc  = fromSeconds gcSec  + fromMicroseconds gcUsec}
  21.     end
  22.  
  23.     fun checkCPUTimer {usr, sys, gc} = 
  24.     let val {gcSec, gcUsec, sysSec, sysUsec, usrSec, usrUsec} 
  25.             = getrutime_ () 
  26.     in {usr = fromSeconds usrSec + fromMicroseconds usrUsec - usr,
  27.         sys = fromSeconds sysSec + fromMicroseconds sysUsec - sys,
  28.         gc  = fromSeconds gcSec  + fromMicroseconds gcUsec  - gc}
  29.     end
  30.  
  31.     fun startRealTimer () = now ();
  32.  
  33.     fun checkRealTimer time1 = now () - time1;
  34.  
  35. (* Removed 1995-11-03, added again 1997-03-07 *)
  36.  
  37.     val totalCPUTime  = startCPUTimer ();
  38.     val totalRealTime = startRealTimer ();
  39.  
  40.     fun totalCPUTimer _  = totalCPUTime;
  41.     fun totalRealTimer _ = totalRealTime;
  42.  
  43. end
  44.